var prefix = jsctx + "/shopGoods";

var shopOrdered = (function (v) {
    function init(v) {
        setTimeout(function () {//防止先于-读取缓存执行
            load(v);
        }, 10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 85;


    function load(k) {

        var transferType = $("#transferType").val();
        var isVerification = $("#isVerification").val();

        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'GET',
                    url: prefix + "/listPageShopGood",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    // cache: false,
                    pageSize: 10,
                    pageList: [10, 20, 30],
                    pageNumber: 1,
                    sidePagination: "server",
                    paginationShowPageGo: true,
                    // contentType : "application/x-www-form-urlencoded",
                    // rightFixedColumns: true,
                    height: h,
                    queryParams: function (params) {

                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            goodsName: $("#nickname").val().trim(),
                            classType: $("#salePlatform").val(),
                            salePlatform: $("#refundBy").val().trim(),
                            // refundSource: $("#refundSource").val().trim(),
                            // outTradeNo: $("#outTradeNo").val().trim(),
                            // refundBy: $("#refundBy").val().trim(),
                            // memberMobile: $("#memberMobile").val().trim(),
                            // memberRealName: $("#memberRealName").val().trim(),
                            status: $("#status").val().trim(),
                            startTime: $("#startTime").val().trim(),
                            endTime: $("#endTime").val().trim(),
                            consignee:'',
                            phone:'',
                            adress:''
                        };
                    },
                    columns: [

                        {
                            title: '#', field: '', width: '50', align: 'center',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'goodsId', title: '商品编号', align: 'center', width: '100'},
                        {field: 'goodsImage', title: '商品缩略图', width: '220', align: 'left',height: '200',
                            formatter:function (value, row, index) {
                            var z = ''
                                z = '<img  src="'+k+value+'" >'
                                return z;
                            }

                        },
                        {field: 'goodsName', title: '商品名称', width: '110', align: 'center'},
                        {
                            field: 'classType', title: '商品属性',
                            width: '80', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '实体商品'
                                } else if (value == '1') {
                                    return '虚拟商品'
                                } else if (value == '2') {
                                    return '第三方商品'
                                }
                            }

                        },
                        {field: 'salePlatform', title: '兑换方式', width: '80', align: 'center',
                        formatter: function (value, row, index) {
                            if (value == '0') {
                                return '线上'
                            } else if (value == '1') {
                                return '线下'
                            } else if (value == '2') {
                                return '快递邮寄'
                            }
                        }
                        },
                        {field: 'goodsPoint', title: '积分单价', width: '80', align: 'center'},
                        {field: 'goodsPrice', title: '实际单价（元）', width: '80', align: 'center'},
                        {field: 'stockNum', title: '商城显示库存', width: '80', align: 'center',
                        formatter:function (value,row,index) {
                                return value - row.stockLockedCount;
                        }},
                        {field: 'stockNum', title: '本地实际库存', width: '80', align: 'center'},
                        {field: 'saleType', title: '支付方式', width: '100', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '积分兑换'
                                } else if (value == '1') {
                                    return '人民币购买'
                                } else if (value == '2') {
                                    return '积分,人民币'
                                }
                            }},
                        {field: 'createdTime', title: '添加时间', width: '120', align: 'center'},

                        {field: 'exchangeNum', title: '已兑换数量', width: '80', align: 'center'},
                        {field: 'status', title: '商品状态', width: '100', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '未上架'
                                } else if (value == '1') {
                                    return '销售中'
                                } else if (value == '10') {
                                    return '已下架'
                                }
                            }},
                        {field: 'consignee', title: '退货信息', width: '80', align: 'center',
                            formatter: function (value, row, index) {
                                if (row.salePlatform == '0') {
                                    return '-'
                                } else if(row.salePlatform == '1'){
                                    return '-'
                                }else{
                                    return '有'
                                }
                            }},
                        {field: 'remark', title: '备注', width: '100', align: 'center'},

                        // {field: 'remark', title: '失败原因', width: '100', align: 'left'},
                        {

                            field: 'roleId',
                            title: '操作',
                            width: '200', align: 'center',
                            class: 'operate-td',
                            formatter: function (value, row, index) {
                                var a = '';
                                var b = '';
                                var c = '';
                                var e = '';
                                var f = '';
                                var g = '';


                                    // g =' <a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="通过" onclick="shopOrdered.updateStatusForPassVerification()">补货</a>'
                                    a = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="通过" onclick="shopOrdered.updateStatusForPass(\''
                                        + row.goodsName + '\',' + '\'' + row.goodsId
                                        + '\')">下架</a> ';
                                    f = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="通过" onclick="shopOrdered.downdateStatusForPass(\''
                                    + row.goodsName + '\',' + '\'' + row.goodsId
                                    + '\')">上架</a> ';
                                    g = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="详情" onclick="shopOrdered.editGoods(\''
                                    + row.goodsId
                                    + '\')">编辑</a> ';
                                    e = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="通过" onclick="shopOrdered.updateStatusForPassVerification(\''
                                        + row.stockNum + '\',' + '\'' + row.goodsId +

                                        '\')">补货</a> ';
                                    b = '<a class="btn btn-danger btn-sm ' + has_edit + '" href="#" title="" onclick="shopOrdered.updateStatusForOverrule(\''
                                        + row.stockNum + '\',' + '\'' + row.goodsId
                                        + '\')">减货</a> ';


                                    c = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="详情" onclick="shopOrdered.getMemberRefundApplyDetail(\''
                                        + row.goodsId
                                        + '\')">库存明细</a> ';

                                var d = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="已到账" onclick="shopOrdered.updateStatusForArrive(\''
                                    + row.goodsId + '\',' + '\'' + row.consignee + '\',' + '\'' + row.phone + '\',' + '\'' +row.address
                                    + '\')">退货信息</a> ';

                                if (row.status == 0) {

                                    return  f+g;
                                    }
                                else if(row.status == 1)
                        {
                                    if (row.salePlatform == 2)
                                    {return  a+e+b+c+d}
                                    else{
                                        return  a+e+b+c
                            }
                        }

                                else{
                                return f+b+c+e;
                                }

                            }
                        }
                    ]
                });
        // $('#exampleTable>tbody>tr>td>img').css('max-width','200px');
        // $('#exampleTable>tbody>tr>td>img').css('max-height','200px');
    }
    function reLoad() {
        // $(".fixed-table-header-columns").css("display", "none");
        // $(".fixed-table-body-columns").css("display", "none");
        $('#exampleTable').bootstrapTable('refresh');
    }

    function addMemberRefundApply() {
        // localStorage.setItem("token", result.accessToken);
        // // ourtoken = localStorage.getItem("token");
        // request.getSession(false);
        var lastname = localStorage.getItem("key");
        // $.ajax({
        //     cache: true,
        //     type: "GET",
        //     url: jsctx + "/tenant/ticket/listAll",
        //     data:sess,
        //     processData: false,
        //     contentType: false,
        //     async: false,
        //     error: function (request) {
        //         isajaxsend = true
        //         parent.layer.alert("Connection error");
        //     },
        //     success: function (data) {
        //         if (data.status == 200) {
        //
        //             parent.layer.msg("操作成功");
        //
        //         } else {
        //
        //             parent.layer.alert(data.message)
        //         }
        //
        //     }
        // });
        location.href = jsctx + "/templates/shopGoods/addShop.jsp"
    }
    function editGoods(goodsId) {
        location.href = jsctx + "/templates/shopGoods/shopGoodsEdit.jsp?goodsId="+goodsId
    }
    function getMemberRefundApplyDetail(goodsId) {
        // location.href = prefix + "/listPageHistory/" + goodsId;
        location.href = jsctx + "/templates/shopGoods/shopNumber.jsp?goodsId="+goodsId
        // location.href =  + '?goodsId=' +goodsId;
}

    var isajaxsendForPass = true;
    function downdateStatusForPass(goodsName,goodsId) {
        var charge = goodsId;
        var chat = goodsName;

        var html = "<div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:18px'>商品名称：</div><span style='font-size: 18px'>"+ chat +"</span></div><div style='font-size:18px;width:90%;margin-left:15px;margin-top:15px'>温馨提示：商品上架后，用户可在手机端兑换该商品，商品对应信息不可编辑，只能调整货物数量，是否确认上架？</div>"
        layer.open({
                type:1,
                title:'商品上架',
                btn:['取消','确认'],
                area:['400px','250px'],
                content:html,



                yes: function () {
                    layer.close(layer.index);
                    reLoad();
                    // }
                },
                btn2:function () {
                    // alert(1)
                    // if (!isajaxsendForPass) {
                    $.ajax({
                        url: prefix + "/saveOrUpdateShopOrder",
                        type: "POST",
                        data: {
                            'goodsId': charge,
                            'status':'1'

                        },
                        beforeSend: function () {
                            // isajaxsendForPass = true;
                        },
                        success: function (data) {
                            // isajaxsendForPass = true;
                            layer.close();
                            if (data.status == 200) {
                                layer.msg("处理成功");
                                reLoad();
                            } else {
                                // isajaxsendForPass = true;
                                layer.msg(data.message);
                                reLoad();
                            }
                        }
                    });
                }
            }
        )
    }
    function updateStatusForPass(goodsName,goodsId) {
        var charge = goodsId;
        var chat = goodsName;

        var html = "<div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:18px'>商品名称：</div><span style='font-size: 18px'>"+ chat +"</span></div><div style='font-size:18px;width:90%;margin-left:15px;margin-top:15px'>温馨提示：商品下架后用户将不可兑换，之前兑换过的不受影响，下架商品可以再次上架，商品信息不可编辑。是否确认下架该商品？</div>"
        layer.open({
                type:1,
                title:'商品下架',
                btn:['取消','确认'],
                area:['400px','250px'],
                content:html,



                yes: function () {
                   layer.close(layer.index)
                    // layer.close();
                    reLoad();
                    // }
                },
                btn2:function () {
                    // alert(1)
                    // if (!isajaxsendForPass) {
                    $.ajax({
                        url: prefix + "/saveOrUpdateShopOrder",
                        type: "POST",
                        data: {
                            'goodsId': charge,
                            'status':'10'

                        },
                        beforeSend: function () {
                            // isajaxsendForPass = true;
                        },
                        success: function (data) {
                            // isajaxsendForPass = true;
                            layer.close();
                            if (data.status == 200) {
                                layer.msg("处理成功");
                                reLoad();
                            } else {
                                // isajaxsendForPass = true;
                                layer.msg(data.message);
                                reLoad();
                            }
                        }
                    });
                }
            }
        )
    }

    function updateStatusForPassVerification(stockNum,goodsId) {
            // alert(stockNum);
        var charge = goodsId;
        var chat =stockNum;

        var html = "<div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:15px'>剩余库存：</div><span>"+ chat +"</span></div><div><div style='display:inline-block;font-size:15px;margin-left:15px;margin-top:15px'>补货数量</div><div style='margin-left:15px;display:inline-block;'><input id='watg' type='text' style='width: 200px'></div></div><div style='margin-top:15px;'><div style='display:inline-block;margin-top:15px;font-size:15px;margin-left:45px;vertical-align:top;'>备注</div><div style='display:inline-block;vertical-align:top;margin-left:15px;'><textarea name='' id='page-wr' cols='30' rows='5'></textarea></div></div>"
           layer.open({
               type:1,
               title:'商品补货',
               btn:['取消','确认'],
               area:['400px','300px'],
               content:html,



              yes: function () {
                   layer.close(layer.index);
                   reLoad();
                   // }
               },
               btn2:function () {
                   // alert(1)
                   // if (!isajaxsendForPass) {
                   $.ajax({
                       url: prefix + "/addOrReduceShopGoods",
                       type: "GET",
                       data: {
                           'goodsId': charge,
                           'type': '0',
                           'remark':  $('#page-wr').val(),
                           'num': $('#watg').val()

                       },
                       beforeSend: function () {
                           // isajaxsendForPass = true;
                       },
                       success: function (data) {
                           // isajaxsendForPass = true;
                           layer.close();
                           if (data.status == 200) {
                               layer.msg("处理成功");
                               reLoad();
                           } else {
                               // isajaxsendForPass = true;
                               layer.msg(data.message);
                               reLoad();
                           }
                       }
                   });
               }
               }
           )
    }


    function updateStatusForOverrule(stockNum,goodsId) {
        var charge = goodsId;
        var chat =stockNum;

        var html = "<div><div style='display:inline-block;margin-left:15px;margin-top:20px;font-size:15px'>剩余库存：</div><span>"+ chat +"</span></div><div><div style='display:inline-block;font-size:15px;margin-left:15px;margin-top:15px'>减货数量</div><div style='margin-left:15px;display:inline-block;'><input id='watgg' type='text' style='width: 200px'></div></div><div style='margin-top:15px;'><div style='display:inline-block;margin-top:15px;font-size:15px;margin-left:45px;vertical-align:top;'>备注</div><div style='display:inline-block;vertical-align:top;margin-left:15px;'><textarea name='' id='page-wrr' cols='30' rows='5'></textarea></div></div>"
        layer.open({
                type:1,
                title:'商品减货',
                btn:['取消','确认'],
                area:['400px','300px'],
                content:html,



                yes: function () {
                    layer.close(layer.index);
                    reLoad();
                    // }
                },
                btn2:function () {
                    // alert(1)
                    // if (!isajaxsendForPass) {
                    $.ajax({
                        url: prefix + "/addOrReduceShopGoods",
                        type: "GET",
                        data: {
                            'goodsId': charge,
                            'type': '1',
                            'remark':  $('#page-wrr').val(),
                            'num': $('#watgg').val()

                        },
                        beforeSend: function () {
                            // isajaxsendForPass = true;
                        },
                        success: function (data) {
                            // isajaxsendForPass = true;
                            layer.close();
                            if (data.status == 200) {
                                layer.msg("处理成功");
                                reLoad();
                            } else {
                                // isajaxsendForPass = true;
                                layer.msg(data.message);
                                reLoad();
                            }
                        }
                    });
                }
            }
        )
    }


    /*------  验证码  -----*/
    var num1 = 60;
    var ajaxReady = true;

    function getMemberRefundAuthCode() {
        if (ajaxReady) {
            $.ajax({
                url: prefix + "/getMemberRefundAuthCode",
                type: "POST",
                data: $('#authCode').val(),
                beforeSend: function () {
                    ajaxReady = false;
                },
                success: function (data) {
                    if (data.status == 200) {
                        time();

                        function time() {
                            if (num1 == 0) {
                                // $('#authCode').attr("disabled", "disabled")
                                $('#getMemberRefundAuthCode').text("获取验证码");
                                $('#getMemberRefundAuthCode').attr("onclick", 'memberRefundApply.getMemberRefundAuthCode()');
                                ajaxReady = true;
                                num1 = 60;
                            } else {
                                // $('#authCode').removeAttr('disabled')
                                $('#getMemberRefundAuthCode').html(num1 + "秒后重试");
                                $('#getMemberRefundAuthCode').removeAttr('onclick');
                                num1--;
                                setTimeout(function () {
                                    time()
                                }, 1000)
                            }
                        }
                    } else {
                        parent.layer.alert(data.message);
                        $('#authCode').removeAttr('disabled')
                        $('#getMemberRefundAuthCode').text("获取验证码");
                        $('#getMemberRefundAuthCode').attr("onclick", 'memberRefundApply.getMemberRefundAuthCode()');
                        ajaxReady = true;
                        num1 = 60;
                    }

                }
            })


        }
    };

    var isajaxsendForArrive = true;

    function updateStatusForArrive(goodsId,consignee,phone,address) {
        var charge = goodsId;
        var consignee = consignee;
        var phone = phone;
        var address = address;
        // var chat =stockNum;
        if (consignee == 'null'){
            consignee = ''
        }
        if (phone == 'null'){
            phone = ''
        }
        if (address == 'null'){
            address = ''
        }
        var html = "<div><div style='display:inline-block;margin-left:29px;margin-top:20px;font-size:15px'>收件人</div><div style='margin-left:15px;display:inline-block;'><input id='future' type='text' style='width: 250px' value='"+consignee+"'></div></div><div><div style='display:inline-block;font-size:15px;margin-left:15px;margin-top:15px'>收件电话</div><div style='margin-left:15px;display:inline-block;'><input id='future2' type='text' style='width: 250px' value='"+phone+"'></div></div><div><div style='display:inline-block;margin-top:15px;font-size:15px;margin-left:15px;'>退货地址</div><div style='display:inline-block;margin-left:15px;'><input id='future3' type='text' style='width: 250px' value='"+address+"'></div></div>"

        layer.open({
                type:1,
                title:'退货信息',
                btn:['取消','确认'],
                area:['400px','250px'],
                content:html,
            //     function(){
            //         console.log(adress)
            //         document.getElementById("future3").value = adress;
            // },



                yes: function () {
                    layer.close(layer.index);
                    reLoad();
                    // }
                },
                btn2:function () {
                    // alert(1)
                    // if (!isajaxsendForPass) {
                    $.ajax({
                        url: prefix + "/saveOrUpdateShopOrder",
                        type: "POST",
                        data: {
                            'goodsId': charge,
                            'consignee':$('#future').val(),
                            'phone':  $('#future2').val(),
                            'address': $('#future3').val()

                        },
                        beforeSend: function () {
                            // isajaxsendForPass = true;
                        },
                        success: function (data) {
                            // isajaxsendForPass = true;
                            layer.close();
                            if (data.status == 200) {
                                layer.msg("处理成功");
                                reLoad();
                            } else {
                                // isajaxsendForPass = true;
                                layer.msg(data.message);
                                reLoad();
                            }
                        }
                    });
                }
            }
        )
    }

    function goBack() {
        window.history.back();
    }

    function exportMemberRefundApply() {
        $.fileDownload(prefix + "/exportMemberRefundApply", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                nickname: $("#nickname").val().trim(),
                mobile: $("#mobile").val().trim(),
                refundSource: $("#refundSource").val().trim(),
                outTradeNo: $("#outTradeNo").val().trim(),
                refundBy: $("#refundBy").val().trim(),
                memberMobile: $("#memberMobile").val().trim(),
                memberRealName: $("#memberRealName").val().trim(),
                status: $("#status").val().trim(),
                startTime: $("#startTime").val().trim(),
                endTime: $("#endTime").val().trim(),
                count: $("#count").val().trim() == '' ? 0 : $("#count").val().trim(),
                offset: $('.active .page-link').text(),
                limit: $(".page-size").text()
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    }
    function pdselect(s){
        var futureTime = s;
        // reLoad();
        var html = ''
        if(sessionStorage.getItem("verificationCode"))
        {
            html = "<div style='font-size:18px;width:90%;margin-left:15px;margin-top:15px'>您的商品核销码为随机生成，线下兑换的商品请相关工作人员核销订单</div><div id='shopVer' style='font-size: 20px;font-weight: bolder;text-align: center;margin-top: 25px;'>"+ sessionStorage.getItem("verificationCode") +"</div>"

        }
        else{
         html = "<div style='font-size:18px;width:90%;margin-left:15px;margin-top:15px'>您的商品核销码为随机生成，线下兑换的商品请相关工作人员核销订单</div><div id='shopVer' style='font-size: 20px;font-weight: bolder;text-align: center;margin-top: 25px;'>"+ futureTime +"</div>"

        }
        var index =  layer.open({
                type:1,
                title:'商品核销码',
                btn:['刷新','确认'],
                area:['400px','250px'],
                content:html,

                yes: function () {
                    $.ajax({
                        url:prefix + "/updateShopVerificationCode",
                        type:"GET",
                        data:{

                        },
                        success:function (data) {
                            if (data.status == 200){
                                $('#shopVer').html(data.message);
                                sessionStorage.setItem("verificationCode",data.message);
                            }
                        }
                    })
                },
                btn2:function () {
                    layer.close(index)
                }
            }
        );
        // $.ajax({
        //     url: prefix + "/updateShopVerificationCode",
        //     type: "GET",
        //     data: {
        //     },
        //     beforeSend: function () {
        //         // isajaxsendForPass = true;
        //     },
        //
        //     success: function (data) {
        //         // isajaxsendForPass = true;
        //         console.log(data);
        //         layer.close();
        //         if (data.status == 200) {
        //             // layer.msg("处理成功");
        //             var futureTime = data.message;
        //             // reLoad();
        //             var html = "<div style='font-size:18px;width:90%;margin-left:15px;margin-top:15px'>您的商品核销码为随机生成，线下兑换的商品请相关工作人员核销订单</div><div style='font-size: 20px;font-weight: bolder;text-align: center;margin-top: 25px;'>"+ futureTime +"</div>"
        //             layer.open({
        //                     type:1,
        //                     title:'商品核销码',
        //                     btn:['刷新','确认'],
        //                     area:['400px','250px'],
        //                     content:html,
        //                     yes: function () {
        //                         layer.closeAll();
        //                         // reLoad()
        //                         pdselect();
        //                     },
        //                     btn2:function () {
        //                     layer.closeAll();
        //                     }
        //                 }
        //             )
        //         } else {
        //             // isajaxsendForPass = true;
        //             layer.msg(data.message);
        //             reLoad();
        //
        //         }
        //     }
        // });


    }
    function memberAdd(a,b,c,d) {
        isajaxsendForPass = false;
        var number = b.length;
        // var money = c;
        // var money = Math.round(Math.round((c*100)/100));
        var money = Math.floor(c*100) / 100;
        layer.open({
                title:'批量处理',
                area:['300px','200px'],
                content:'勾选数量:'+ number + '</br>'+ '需退款金额:' + money,
                // + '</br>' + '备注:' + '</br>' + '<textarea id="sefix" rows="4" cols="33"></textarea>'
                btn: ['取消','批量处理','批量驳回',],
                yes:function(index,layero){
                    layer.close(index);
                },

                btn2:function(index,layero){
                    // console.log($('#isVerification').val());
                    if($('#isVerification').val() == '0')
                    { $('#exampleModalVerification').modal('show');
                        // console.log($("#sefix").val());
                        // var text = $("#sefix").val();
                        $("#submitVerificationForm").unbind("click").bind("click", function () {
                            var formData = new FormData();
                            formData.append("refundApplyIdsJson",d);
                            formData.append("status", "1");
                            formData.append("authCode", $("#authCode").val());
                            // formData.append("remark", text);
                            var isajaxVerification = true;

                            if (isajaxVerification) {
                                $.ajax({
                                    url: prefix + "/batchUpdateMemberRefundApplyStuts",
                                    type: "post",
                                    data: formData,
                                    dataType: "json",
                                    processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                                    contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                                    beforeSend: function () {
                                        isajaxVerification = false;
                                    },
                                    success: function (data) {

                                        if (data.status == 200 && data.message == "") {
                                            isajaxVerification = true;
                                            parent.layer.msg("操作成功");
                                            $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                                document.getElementById("contentFormVerification").reset();
                                            })
                                            $('#exampleModalVerification').modal('hide');
                                            reLoad();
                                        }
                                        else if(data.status == 200 && data.message != ""){
                                            isajaxVerification = true;
                                            // parent.layer.msg("操作成功");
                                            $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                                document.getElementById("contentFormVerification").reset();
                                            });
                                            $('#exampleModalVerification').modal('hide');
                                            layer.open({
                                                title:'信息提示',
                                                area:['300px','200px'],
                                                content:data.message,
                                                btn: ['确定']

                                            });
                                            reLoad();
                                        }else {
                                            isajaxVerification = true;
                                            parent.layer.alert(data.message);
                                            $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                                document.getElementById("contentFormVerification").reset();
                                            });
                                            $('#exampleModalVerification').modal('hide');
                                            reLoad();
                                        }

                                    }
                                })
                            }

                        })}
                    if($('#isVerification').val() == '1'){
                        var formData = new FormData();
                        formData.append("refundApplyIdsJson",d);
                        formData.append("status", "1");
                        var isajaxVerification = true;
                        if (isajaxVerification) {
                            $.ajax({
                                url: prefix + "/batchUpdateMemberRefundApplyStuts",
                                type: "post",
                                data: formData,
                                dataType: "json",
                                processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                                contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                                beforeSend: function () {
                                    isajaxVerification = false;
                                },
                                success: function (data) {
                                    if (data.status == 200 && data.message == "") {
                                        isajaxVerification = true;
                                        parent.layer.msg("操作成功");
                                        $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                            document.getElementById("contentFormVerification").reset();
                                        })
                                        $('#exampleModalVerification').modal('hide');
                                        reLoad();
                                    }
                                    else if(data.status == 200 && data.message != ""){
                                        isajaxVerification = true;
                                        // parent.layer.msg("操作成功");
                                        $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                            document.getElementById("contentFormVerification").reset();
                                        })
                                        $('#exampleModalVerification').modal('hide');
                                        layer.open({
                                            title:'信息提示',
                                            area:['300px','200px'],
                                            content:data.message,
                                            btn: ['确定']

                                        });
                                        reLoad();
                                    }
                                    else {
                                        isajaxVerification = true;
                                        parent.layer.alert(data.message);
                                        $('#exampleModalVerification').on('hidden.bs.modal', function () {
                                            document.getElementById("contentFormVerification").reset();
                                        })
                                        $('#exampleModalVerification').modal('hide')
                                        reLoad();
                                    }
                                }
                            })}}

                },
                btn3:function(index,layero){

                    $('#exampleModal').modal('show')

                    $("#submitForm").unbind("click").bind("click", function () {

                        var formData = new FormData();
                        formData.append("remark", $("#remark").val());
                        formData.append("refundApplyIdsJson",d);
                        formData.append("status", "2");
                        $.ajax({
                            url: prefix + "/batchUpdateMemberRefundApplyStuts",
                            type: "post",
                            data: formData,
                            dataType: "json",
                            processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                            contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                            success: function (data) {
                                if (data.status == 200 && data.message == "") {
                                    // layer.msg("操作成功");
                                    parent.layer.msg("操作成功");
                                    $('#exampleModal').on('hidden.bs.modal', function () {
                                        document.getElementById("contentForm").reset();
                                    })
                                    $('#exampleModal').modal('hide')
                                    reLoad();
                                }
                                else if(data.status == 200 && data.message != "")
                                {
                                    // layer.msg("请填写备注");
                                    $('#exampleModal').on('hidden.bs.modal', function () {
                                        document.getElementById("contentForm").reset();
                                    })
                                    $('#exampleModal').modal('hide')
                                    layer.open({
                                        title:'信息提示',
                                        area:['300px','200px'],
                                        content:data.message,
                                        btn: ['确定']

                                    })
                                    reLoad();

                                }
                                else {
                                    // layer.msg('操作失败');
                                    parent.layer.alert(data.message);
                                    $('#exampleModal').on('hidden.bs.modal', function () {
                                        document.getElementById("contentForm").reset();
                                    })
                                    $('#exampleModal').modal('hide')
                                    reLoad();
                                }

                            }
                        })
                    })


                }
            }

        )
    }

    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        updateStatusForPass: updateStatusForPass,
        updateStatusForOverrule: updateStatusForOverrule,
        addMemberRefundApply: addMemberRefundApply,
        getMemberRefundApplyDetail: getMemberRefundApplyDetail,
        updateStatusForArrive: updateStatusForArrive,
        exportMemberRefundApply: exportMemberRefundApply,
        updateStatusForPassVerification: updateStatusForPassVerification,
        getMemberRefundAuthCode: getMemberRefundAuthCode,
        memberAdd: memberAdd,
        pdselect:pdselect,
        downdateStatusForPass:downdateStatusForPass,
        editGoods:editGoods
    };
})();

var addMemberRefundApply = (function () {
    function init() {
        validateRule();
    };

    function getCheckedRoles() {
        var adIds = "";
        $("input:checkbox[name=role]:checked").each(function (i) {
            if (0 == i) {
                adIds = $(this).val();
            } else {
                adIds += ("," + $(this).val());
            }
        });
        return adIds;
    }

    var isajaxsend = true;

    function save() {
        if ($("select[name='refundBy']").val() == "2") {
            if ($("select[name='refundBankCode']").val() == "" || $("select[name='refundBankCode']").val() == null) {
                var str = "<label class='error couponError' ><i class='fa fa-times-circle'></i>请选择银行</label>"
                $(".refundBankCodeDiv").append(str)
                return;
            }
        }


        if (isajaxsend) {
            var formData = new FormData($("#frmMemberRefundApply")[0]);
            $("#roleIds").val(getCheckedRoles());
            $.ajax({
                cache: true,
                type: "POST",
                url: prefix + "/saveMemberRefundApply",
                data: formData,
                processData: false,
                contentType: false,
                async: false,
                beforeSend: function () {
                    isajaxsend = false
                },
                error: function (request) {
                    isajaxsend = true
                    parent.layer.alert("Connection error");
                },
                success: function (data) {
                    if (data.status == 200) {
                        isajaxsend = false
                        parent.layer.msg("操作成功");
                        window.history.back();
                    } else {
                        isajaxsend = true
                        parent.layer.alert(data.message)
                    }

                }
            });
        }
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#frmMemberRefundApply").validate({
            rules: {
                // memberMobile: {
                //     required: true
                // },
                // memberRealName: {
                //     required: true
                // },
                refundAmount: {
                    required: true,
                    min: 1
                },
                refundSource: {
                    required: true,
                },

            },
            messages: {
                // memberMobile: {
                //     required: icon + "请输入提现账户号码"
                // },
                // memberRealName: {
                //     required: icon + "请输入真实姓名"
                // },
                refundAmount: {
                    required: icon + "请输入退款金额",
                    min: icon + "请输入大于1的金额",
                },
                refundSource: {
                    required: icon + "请选择用户充电端",
                },
            },
            submitHandler: function (form) {
                save();
            }
        })
    }

    return {
        init: init
    };
})();
